[LaTeX] breaking an environment across pages - the smart way

Posted by Flavius on Stack Overflow See other posts from Stack Overflow or by Flavius
Published on 2010-05-13T17:45:37Z Indexed on 2010/05/13 17:54 UTC
Read the original article Hit count: 298

Filed under:

Hi

I am using the exercise package to display exercises in a book. I have redefined some commands like this, which basically adds some space, a pencil, and two hrule's before and after the exercise:

\renewcommand{\ExerciseHeader}{\vskip 1em\hrule\vskip 1em\centerline{\textbf{\large\smallpencil
\ExerciseHeaderNB\ExerciseHeaderTitle%
\ExerciseHeaderDifficulty\ExerciseHeaderOrigin\medskip}}}
\makeatletter\def\endExerciseEnv{\termineliste{1}\@EndExeBox\vskip .5em\hrule\vskip 1em}\makeatother

Now this works, but there's a small problem:

There are situations where only the \hrule ends up being at the bottom of a page, and the rest of the exercise goes on the next page. There is also the opposite behavior: the entire exercise is on one page, except the \hrule in "endExerciseEnv", which is flushed to the next page.

My question is:

How to force the top hrule come

  • either together with the header of the exercise (caption, title, whatever not) and at least the first two paragraphs (or \ExePath and a paragraph, or anything like that, but there must be at last "two things", so it doesn't look ugly),
  • OR be flushed altogether, with the entire exercise?

Similar question for the bottom hrule: How to force it have at least two items in front of it on the visible page where the hrule itself goes to?

Any LaTeX guru who knows that?

Addendum

I have asked in the past LaTeX questions like this and I've got answers which required me to do stuff manually, like "insert a \vskip here and there" or such. Let me be clear: This is a book, there's lot of exercises, and I NEED it be done "automatically", by going the proper way of redeclaring commands & co.

© Stack Overflow or respective owner

Related posts about latex